package com.data.modules.online.cgreport.service.impl;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.data.common.exception.BootException;
import com.data.common.util.ConvertUtils;
import com.data.modules.online.cgreport.entity.OnlCgreportHead;
import org.apache.commons.lang.StringUtils;
import com.data.common.system.api.ISysBaseAPI;
import com.data.modules.online.cgreport.service.IOnlCgreportAPIService;
import com.data.modules.online.cgreport.service.IOnlCgreportItemService;
import com.data.modules.online.cgreport.service.IOnlCgreportParamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("onlCgreportAPIService")
public class OnlCgreportAPIService implements IOnlCgreportAPIService {

    private static final Logger logger = LoggerFactory.getLogger(OnlCgreportAPIService.class);
    @Autowired
    private OnlCgreportHeadServiceImpl onlCgreportHeadService;
    @Autowired
    private IOnlCgreportItemService onlCgreportItemService;
    @Autowired
    private IOnlCgreportParamService onlCgreportParamService;
    @Autowired
    private ISysBaseAPI sysBaseAPI;

    private static /* synthetic */ java.lang.Object m336a(java.lang.invoke.SerializedLambda r3) {
        /*
        // Method dump skipped, instructions count: 118
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgreport.service.p016a.OnlCgreportAPIService.m336a(java.lang.invoke.SerializedLambda):java.lang.Object");
    }

    @Override
    public Map<String, Object> getDataById(String id, Map<String, Object> params) {
        return getData(id, null, params);
    }

    @Override
    public Map<String, Object> getDataByCode(String code, Map<String, Object> params) {
        return getData(null, code, params);
    }

@Override
public java.util.Map<java.lang.String, java.lang.Object> getData(java.lang.String id, java.lang.String code, java.util.Map<java.lang.String, java.lang.Object> params) {
        OnlCgreportHead var4 = null;
        if (ConvertUtils.isNotEmpty(id)) {
            var4 = (OnlCgreportHead)this.onlCgreportHeadService.getById(id);
        } else if (ConvertUtils.isNotEmpty(code)) {
            LambdaQueryWrapper<OnlCgreportHead> var5 = new LambdaQueryWrapper();
            var5.eq(OnlCgreportHead::getCode, code);
            var4 = (OnlCgreportHead)this.onlCgreportHeadService.getOne(var5);
        }

        if (var4 == null) {
            throw new BootException("实体不存在");
        } else {
            try {
                String var8 = var4.getCgrSql().trim();
                String var6 = var4.getDbSource();
                return this.executeSelectSqlRoute(var6, var8, params, var4.getId());
            } catch (Exception var7) {
                logger.error(var7.getMessage(), var7);
                throw new BootException("SQL执行失败：" + var7.getMessage());
            }
        }
    }

    @Override
    public Map<String, Object> executeSelectSqlRoute(String dbKey, String sql, Map<String, Object> params, String headId) throws Exception {
        if (StringUtils.isNotBlank(dbKey)) {
            return this.onlCgreportHeadService.executeSelectSqlDynamic(dbKey, sql, params, headId);
        }
        return this.onlCgreportHeadService.executeSelectSql(sql, headId, params);
    }
}
